package com.business_clean.ui.adapter.roster;

import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.business_clean.R;
import com.business_clean.app.config.Constant;
import com.business_clean.app.weight.CustomAvatarView;
import com.business_clean.data.mode.roster.RosterList;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import org.jetbrains.annotations.NotNull;

import me.hgj.mvvmhelper.ext.LogExtKt;

public class RosterAdapter extends BaseQuickAdapter<RosterList, BaseViewHolder> {

    public RosterAdapter() {
        super(R.layout.item_roster);
        addChildClickViewIds(R.id.iv_item_roster_call);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, RosterList item) {
        holder.setText(R.id.tv_item_roster_name, item.getUser_name());

        CustomAvatarView avatarView = holder.getView(R.id.iv_item_roster_avatar);
        avatarView.setAvatar(item.getAvatar(), item.getUser_name());
        avatarView.getAvatarText().setTextSize(16f);

        //区分标签类的内容

        TextView tvIDCard = holder.getView(R.id.tv_item_idcard);
        TextView tvBank = holder.getView(R.id.tv_item_bank);
        TextView tvContact = holder.getView(R.id.tv_item_contact);
        TextView tvBody = holder.getView(R.id.tv_item_body);
        TextView tvCrime = holder.getView(R.id.tv_item_recode_check);


        if ("1".equals(item.getIs_out())) {//是否为外部人员，外部人员，不需要显示以下信息 只显示岗位名称
            if (!TextUtils.isEmpty(item.getJob_name())) {
                holder.setText(R.id.tv_item_roster_desc, item.getJob_name());
            } else {
                holder.setText(R.id.tv_item_roster_desc, "外部人员");
            }
            tvIDCard.setVisibility(View.GONE);
            tvBank.setVisibility(View.GONE);
            tvContact.setVisibility(View.GONE);
            tvBody.setVisibility(View.GONE);
        } else { //总部成员
            if ("1".equals(item.getIs_head_office())) {//是总部人员
                holder.setText(R.id.tv_item_roster_desc, "总部成员");
                tvIDCard.setVisibility(View.GONE);
                tvBank.setVisibility(View.GONE);
                tvContact.setVisibility(View.GONE);
                tvBody.setVisibility(View.GONE);
                tvCrime.setVisibility(View.GONE);
            } else {//项目成员

                StringBuilder stringBuilder = new StringBuilder();
                if (!TextUtils.isEmpty(item.getSex_name())) {
                    stringBuilder.append(item.getSex_name());
                }
                if (!TextUtils.isEmpty(item.getJob_name())) {
                    stringBuilder.append(" / ").append(item.getJob_name());
                }
                if (!TextUtils.isEmpty(item.getAge())) {
                    stringBuilder.append(" / ").append(item.getAge()).append("岁");
                }
                if (!TextUtils.isEmpty(item.getWork_age())) {
                    stringBuilder.append(" / ").append(item.getWork_age() + "").append("年");
                }
                holder.setText(R.id.tv_item_roster_desc, stringBuilder.toString());

                tvIDCard.setVisibility(View.VISIBLE);
                tvBank.setVisibility(View.VISIBLE);
                tvContact.setVisibility(View.VISIBLE);
                tvBody.setVisibility(View.VISIBLE);
                tvCrime.setVisibility(View.VISIBLE);

                //身份
                if ("1".equals(item.getIs_has_id_card())) {
                    tvIDCard.setTextColor(ContextCompat.getColor(tvIDCard.getContext(), R.color.base_primary));
                    tvIDCard.setBackgroundResource(R.color.base_primary_select);
                } else {
                    tvIDCard.setTextColor(ContextCompat.getColor(tvIDCard.getContext(), R.color.base_primary_disable_2));
                    tvIDCard.setBackgroundResource(R.color.base_primary_bg_page);
                }

                //银行卡
                if ("1".equals(item.getIs_has_bank_card())) {
                    tvBank.setTextColor(ContextCompat.getColor(tvBank.getContext(), R.color.base_primary));
                    tvBank.setBackgroundResource(R.color.base_primary_select);
                } else {
                    tvBank.setTextColor(ContextCompat.getColor(tvBank.getContext(), R.color.base_primary_disable_2));
                    tvBank.setBackgroundResource(R.color.base_primary_bg_page);
                }

                //合同
                if ("1".equals(item.getIs_has_contract())) {
                    tvContact.setTextColor(ContextCompat.getColor(tvContact.getContext(), R.color.base_primary));
                    tvContact.setBackgroundResource(R.color.base_primary_select);
                } else {
                    tvContact.setTextColor(ContextCompat.getColor(tvContact.getContext(), R.color.base_primary_disable_2));
                    tvContact.setBackgroundResource(R.color.base_primary_bg_page);
                }

                //健康证明
                if ("1".equals(item.getIs_has_healthy_card())) {
                    tvBody.setTextColor(ContextCompat.getColor(tvBody.getContext(), R.color.base_primary));
                    tvBody.setBackgroundResource(R.color.base_primary_select);
                } else {
                    tvBody.setTextColor(ContextCompat.getColor(tvBody.getContext(), R.color.base_primary_disable_2));
                    tvBody.setBackgroundResource(R.color.base_primary_bg_page);
                }

                //无犯罪
                if ("1".equals(item.getIs_has_healthy_card())) {
                    tvCrime.setTextColor(ContextCompat.getColor(tvCrime.getContext(), R.color.base_primary));
                    tvCrime.setBackgroundResource(R.color.base_primary_select);
                } else {
                    tvCrime.setTextColor(ContextCompat.getColor(tvCrime.getContext(), R.color.base_primary_disable_2));
                    tvCrime.setBackgroundResource(R.color.base_primary_bg_page);
                }
            }
        }

    }
}